const express = require('express');
const app = express();
const url = require('url');
app.use((req, res, next) => {
    res.setHeader("Access-Control-Allow-Origin", '*')
    res.setHeader("Access-Control-Allow-Headers", '*')
    next();
})

app.get('/user', (req, res, next) => {
    const {query} = url.parse(req.url, true);
    res.setHeader('Content-Type', 'application/json;charset="utf8"');
    res.send(query);
    next();
})

app.post('/user', (req, res, next) => {
    const chunks = [];
    req.on('data', (data) => {
        chunks.push(data);
    })
    req.on('end', () => {
        const r = Buffer.concat(chunks).toString();
        res.send(r);
    })
})


app.listen(3000, () => {
    console.log('server is running at 3000');
})